package dp;

import java.util.Scanner;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class allBag {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int V= sc.nextInt();
        int[] weight = new int[N];
        int[] value = new int[N];
        for (int i=0; i<N ;i++ ){
            weight[i] = sc.nextInt();
            value[i] = sc.nextInt();
        }
        int[] dp = new int[V + 1];
        for (int i = 0; i < N ; i++)
            for (int j = weight[i];j <= V; j++){
                dp[j] = Math.max(dp[j], dp[j - weight[i]] + value[i]);
            }
        System.out.println(dp[V]);
    }
}
